package com.gzbsoft.sc.common.config;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Optional;
public class Json2LongConverter extends JsonSerializer<Optional<LocalDateTime>> {
    @Override
    public void serialize(Optional<LocalDateTime> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeNumber(value.map(date -> date.toInstant(ZoneOffset.of("+8")).toEpochMilli()).orElse(0L));
    }
}
